// Name: jQuery.DynamicPopulate.DynamicPopulateExtender.debug.js
// Assembly: AjaxControlToolkit
// Version: 3.5.7.1213
// FileVersion: 3.5.7.1213
// (c) 2010 CodePlex Foundation
(function(window, $) {
$act.createWidget('dynamicPopulateExtender', {
options: {
clearContentsDuringUpdate: true,
contextKey: null,
servicePath: null,
serviceMethod: null,
populateTriggerID: null,
cacheDynamicResults: false,
updatingCssClass: "",
customScript: ""
},
_events: [
"populating", "populated"
],
_create: function() {
var self = this, opt = self.options;
self._clickHandler = null;
self._callID = 0;
self._currentCallID = -1;
self._oldCss = null;
self._populated = false;
if (opt.populateTriggerID) {
$('#' + opt.populateTriggerID).click(function () {
self.populate(opt.contextKey);
});
}
},
populate: function (contextKey) {
///
/// Get the dymanic content and use it to populate the target element
///
///
/// An arbitrary string value to be passed to the web method. For example, if the element to be
/// populated is within a data-bound repeater, this could be the ID of the current row.
///
if (contextKey)
this._setOption("contextKey", contextKey);
var self = this,
opt = self.options;
if (opt.populated && opt.cacheDynamicResults) {
return;
}
if (self._currentCallID == -1) {
var eventArgs = new $act.args.cancelEventArgs();
self.raisePopulating(eventArgs);
if (eventArgs.get_cancel()) {
return;
}
self._setUpdating(true);
}
if (opt.customScript) {
var scriptResult = eval(opt.customScript);
self._setTargetHtml(scriptResult);
self._setUpdating(false);
} else {
self._currentCallID = ++self._callID;
var servicePath = opt.servicePath || location.pathname,
serviceMethod = opt.serviceMethod;
if (servicePath || serviceMethod) {
var url = servicePath
? servicePath + "/" + encodeURIComponent(serviceMethod)
: encodeURIComponent(serviceMethod),
ctxKey = (contextKey ? contextKey : opt.contextKey);
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({ contextKey: ctxKey })
}).done(function (result) {
if (result && result.d)
result = result.d;
self._onMethodComplete(result, self._currentCallID);
}).fail(function(xhr) {
self._onMethodError(xhr, self._currentCallID);
});
}
}
},
_onMethodComplete: function (result, userContext, methodName) {
///
/// Callback used when the populating service returns successfully
///
///
/// The data returned from the Web service method call
///
///
/// The context information that was passed when the Web service method was invoked
///
///
/// The Web service method that was invoked
///
if (userContext != this._currentCallID) return;
this._setTargetHtml(result);
this._setUpdating(false);
},
_onMethodError: function (webServiceError, userContext, methodName) {
///
/// Callback used when the populating service fails
///
///
/// Web service error
///
///
/// The context information that was passed when the Web service method was invoked
///
///
/// The Web service method that was invoked
///
if (userContext != this._currentCallID) return;
if (webServiceError.statusText == "timeout") {
this._setTargetHtml($act.resources.DynamicPopulate_WebServiceTimeout);
} else {
this._setTargetHtml($act.string.format($act.resources.DynamicPopulate_WebServiceError, webServiceError.status));
}
this._setUpdating(false);
},
_setUpdating: function (updating) {
///
/// Toggle the display elements to indicate if they are being updated or not
///
///
/// Whether or not the display should indicated it is being updated
///
var self = this;
self.setStyle(updating);
if (!updating) {
self._currentCallID = -1;
self._populated = true;
self.raisePopulated(this);
}
},
_setTargetHtml: function (value) {
///
/// Populate the target element with the given value
///
///
/// The data to populate the target element.
///
var e = $(this.element);
if (e) {
if (e.is('input')) {
e.val(value);
} else {
e.html(value);
}
}
},
setStyle: function (updating) {
///
/// Set the style of the display
///
///
/// Whether or not the display is being updated
///
var self = this, opt = self.options, e = $(self.element);
if (opt.updatingCssClass) {
if (!updating) {
e.removeClass().addClass(self._oldCss);
self._oldCss = null;
} else {
self._oldCss = e.attr('class');
e.removeClass().addClass(opt.updatingCssClass);
}
}
if (updating && opt.clearContentsDuringUpdate) {
self._setTargetHtml("");
}
}
});
})(window, actJQuery);